use "Replication/tobit_data.dta"，clear

sort ccode year
//set panel data format
xtset ccode year


label variable distance_idealpoint_chnlog_lag1 "与中国的外交立场距离"
label variable swap_dummy_lag1 "货币互换协定"
label variable polity2_lag1 "政体分值"
label variable gdppc_log_lag1 "人均国民生产总值"
label variable pop_log_lag1 "人口总数"
label variable milexp_lag1 "军费开支比重"
label variable dep_export_lag1 "对中国出口贸易依赖度"
label variable dep_import_lag1 "对中国进口贸易依赖度"
label variable arms_exportfromchnlog_lag1 "对中军售出口总额"
label variable arms_importtochnlog_lag1 "对中军事进口总额"
label variable bits_chn_lag1 "双边投资协议"
label variable pta_china_lag1 "贸易优惠协定"
label variable sco_full_lag1 "上合组织成员国"
label variable asean_memb_lag1 "东盟成员国"
label variable minidist_log_lag1 "与中国的地理距离"
label variable partner_level_lag1 "中国外交伙伴关系类型"
label variable distance_idealpoint_usalog_lag1 "与美国的外交立场距离"
label variable minidist_usalog_lag1 "与美国的地理距离"
label variable defense_usa_lag1 "与美国防御性盟约"
label variable year "年份"


replace defense_usa =0 if defense_usa ==.

***************************** Appendix Table 1

estpost summarize 	distance_idealpoint_chnlog swap_dummy swap_rmbsizelog gdppc_log pop_log milexp sco_full asean_memb bits_chn pta_china dep_export dep_import polity2 arms_exportfromchnlog arms_importtochnlog partner_level  distance_idealpoint_usalog defense_usa minidist_usalog 
esttab using "des.rtf" , cells("count mean sd min max") label noobs title(Descriptive Summary \label{tab0}) replace


***************************** Appendix Table 4
** use mullevel tobit
*two-level random-intercept model of y on x with ccode nested within year
*base
metobit distance_idealpoint_chnlog distance_idealpoint_chnlog_lag1 swap_dummy_lag1 distance_idealpoint_usalog_lag1 ///
 minidist_usalog_lag1 defense_usa_lag1 i.year || ccode: , ll(0) ul(2)
estimate store t1

*country
metobit distance_idealpoint_chnlog  swap_dummy_lag1 polity2_lag1 gdppc_log_lag1 pop_log_lag1 milexp_lag1 sco_full_lag1 ///
 asean_memb_lag1 i.year || ccode: , ll(0) ul(2)
 estimate store t2


*bilateral
metobit distance_idealpoint_chnlog  distance_idealpoint_chnlog_lag1 swap_dummy_lag1 polity2_lag1 gdppc_log_lag1 pop_log_lag1 ///
 milexp_lag1 dep_export_lag1 dep_import_lag1 arms_exportfromchnlog_lag1 arms_importtochnlog_lag1  bits_chn_lag1 pta_china_lag1 ///
 sco_full_lag1 asean_memb_lag1 minidist_log_lag1 partner_level_lag1 i.year || ccode: , ll(0) ul(2)
estimate store t3

*full

metobit distance_idealpoint_chnlog  distance_idealpoint_chnlog_lag1 swap_dummy_lag1  polity2_lag1 gdppc_log_lag1 pop_log_lag1 milexp_lag1 ///
dep_export_lag1 dep_import_lag1 arms_exportfromchnlog_lag1 arms_importtochnlog_lag1 bits_chn_lag1 pta_china_lag1 sco_full_lag1 ///
asean_memb_lag1 minidist_log_lag1 partner_level_lag1 distance_idealpoint_usalog_lag1 minidist_usalog_lag1 defense_usa_lag1 i.year || ccode: , ll(0) ul(2)
estimate store t4


*use
metobit distance_idealpoint_chnlog  distance_idealpoint_chnlog_lag1 swap_dummy_lag1 polity2_lag1 gdppc_log_lag1 pop_log_lag1 milexp_lag1 ///
dep_export_lag1 dep_import_lag1  arms_exportfromchnlog_lag1 arms_importtochnlog_lag1 bits_chn_lag1 pta_china_lag1 sco_full_lag1 asean_memb_lag1 ///
minidist_log_lag1 partner_level_lag1 distance_idealpoint_usalog_lag1 minidist_usalog_lag1 defense_usa_lag1 i.year || ccode: , ll(0) ul(2)
estimate store t5


esttab t1 t2 t3 t4 t5 using "metobit.rtf",se parentheses ///
	nonumbers mtitles("模型1" "模型2" "模型3" "模型4" "模型5") ///
  star(* 0.10 ** 0.05 *** 0.01)  replace 
  
